var Script = function () {

    //$.validator.setDefaults({
    //    submitHandler: function() {
    //
    //        console.log()
    //
    //    }
    //});

    $().ready(function() {
        // validate the comment form when it is submitted
        $("#addUserForm").validate({
            rules: {
                password: "required",
                rpassword: {
                    equalTo: "#cpassword"
                }
            },
            messages: {
                name: "请填写用户名",
                password: "请输入密码",
                rpassword: "请再输入一次密码",
                email: "请输入正确的邮箱"
            },
            submitHandler: function(){
                var data = {
                    user: $('#cname').val(),
                    pass: $('#cpassword').val(),
                    mail: $('#cemail').val()
                };
                $.ajax({
                    url: 'adminUser/add',
                    data: data,
                    type: "POST",
                    success: function(datas){
                        if(!datas.status){
                            var users = $('<tr data-id="'+ datas.auid +'">' +
                                '<td>'+data.user+'</td>' +
                                '<td>'+data.mail+'</td>' +
                                '<td>' +
                                '<button class="btn btn-primary btn-xs"><i class="icon-pencil"></i></button>&nbsp;' +
                                '<button class="btn btn-danger btn-xs"><i class="icon-trash"></i></button>' +
                                '</td>' +
                                '</tr>');
                            users.prependTo('tbody');
                            $('.modal-header .close').click();
                        }else{
                            alert(datas.msg);
                        }
                    }
                });
            }
        });

    });


}();